//Shirasu Azusa 2024.7
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;  
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=1e6+5;
int n,m,a[N],S[N],P[N],xxx;
char c[N];

struct node {int f,x,y;} f[N<<2];
#define ls (p<<1)
#define rs (p<<1|1)
node operator + (const node x,const node y) {
  node z; z.x=min(x.x,y.x), z.y=min(x.y,y.y);
  z.f=min(min(x.f,y.f),x.x+y.y); return z;
}
void build(int p,int l,int r) {
  if(l==r) {f[p].f=min(0,P[l]+S[l]),f[p].x=P[l],f[p].y=S[l]; return;} int mid=l+r>>1;
  build(ls,l,mid), build(rs,mid+1,r), f[p]=f[ls]+f[rs];
}
node qry(int p,int l,int r,int x,int y) {
  if(l==x&&r==y) return f[p]; int mid=l+r>>1;
  if(y<=mid) return qry(ls,l,mid,x,y);
  else if(x>mid) return qry(rs,mid+1,r,x,y);
  else return qry(ls,l,mid,x,mid)+qry(rs,mid+1,r,mid+1,y);
}

signed main() {
  freopen("good.in","r",stdin);
  freopen("good.out","w",stdout);
  n=read(), m=read(); scanf("%s",c+1);
  rep(i,1,n) a[i]=c[i]-'0';
  rep(i,1,n) if(a[i]==0) a[i]=-1;
  rep(i,1,n) P[i]=P[i-1]+a[i];
  per(i,n,1) S[i]=S[i+1]+a[i];
  build(1,1,n);
  rep(i,1,m) {
    int l=read(), r=read();
    node x=qry(1,1,n,l,r);
    int res=x.f-S[r+1]-P[l-1];
    chmin(res,x.y-S[r+1]);
    chmin(res,x.x-P[l-1]);
    res=-res;
    xxx^=res;
  }
  printf("%d\n",xxx);
  return 0;
}